home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS01.ADF
/
C
/
raw.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-01-09
|
9KB
|
315 lines
/*************************************************************************/
/* */
/* Window */
/* Steve Ahlstrom */
/* */
/*************************************************************************/
#include "exec/types.h"
#include "intuition/intuition.h"
#include "libraries/dos.h"
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Window *Window;
struct RastPort *myrastport;
int oldsize;
SHORT row = 8, column = 0; /* pixel row and column values */
SHORT ctr;
char string[2]; /* stores one character for output */
char line[80]; /* stores line of text for wrap */
char chr;
#define INTUITION_REV 30
#define GRAPHICS_REV 30
#define COLUMN_SIZE 8
struct TextAttr MyFont =
{
"topaz.font", /* Font Name */
TOPAZ_EIGHTY, /* Font Height */
FS_NORMAL, /* Style */
FPF_ROMFONT, /* Preferences */
};
int
Open_Window()
{
struct NewWindow NewWindow;
/* Open the Intuition library, The result returned by this call is
* used to connect your program to the actual Intuition routines
* in ROM. If the result of this call is equal to zero, something
* is wrong and the Intuition you requested is not available, so
* your program should exit immediately.
*/
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", INTUITION_REV);
if(IntuitionBase == NULL)
return(FALSE);
GfxBase = (struct GfxBase *)
OpenLibrary("graphics.library", GRAPHICS_REV);
if(GfxBase == NULL)
return(FALSE);
NewWindow.LeftEdge = 0;
NewWindow.TopEdge = 0;
NewWindow.Width = 320;
NewWindow.Height = 100;
NewWindow.DetailPen = -1;
NewWindow.BlockPen = -1;
NewWindow.Title = "Generic Window Handler";
NewWindow.Flags = WINDOWCLOSE | SMART_REFRESH | ACTIVATE |
WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH |
GIMMEZEROZERO;
NewWindow.IDCMPFlags = CLOSEWINDOW | RAWKEY | REFRESHWINDOW |
NEWSIZE;
NewWindow.Type = WBENCHSCREEN;
NewWindow.FirstGadget = NULL;
NewWindow.CheckMark = NULL;
NewWindow.Screen = NULL;
NewWindow.BitMap = NULL;
NewWindow.MinWidth = 320;
NewWindow.MinHeight = 100;
NewWindow.MaxWidth = 640;
NewWindow.MaxHeight = 200;
if((Window = (struct Window *) OpenWindow(&NewWindow)) == NULL)
return(FALSE);
myrastport = Window->RPort;
return(TRUE);
} /* Open_Window */
void
Close_Window()
{
CloseWindow(Window);
} /* Close_Window */
void
Next_Line_Down()
{
SHORT i;
if(row >= Window->GZZHeight-8) {
for (i=0; i<8; i++) {
ScrollRaster(myrastport, 0, 1, 0, 0,Window->GZZWidth,Window->GZZHeight);
WaitTOF();
}
}
else
row += 8;
} /* Next_Line_Down */
void
Cursor_Toggle() /* dlm 10/23/85 */
/* output a full character block cursor */
{
SetAPen(myrastport, 0); /* color register 0 */
SetDrMd(myrastport, JAM2 | COMPLEMENT);
Move(myrastport, column, row);
Text(myrastport, " ", 1);
SetAPen(myrastport, 1); /* color register 1 */
SetDrMd(myrastport, JAM2);
} /* Cursor_Toggle */
char
raw_to_ascii(keycode, qualifier)
USHORT keycode, qualifier;
/* translate the raw keycode to an ASCII value */
{
static char translate_table[66] =
{ '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\\', 0, '0',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 0, '1', '2', '3',
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', 39, 0, 0, '4', '5', '6',
0, 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '.', '7', '8', '9',
' ', 8
};
static char sym_translate_table[16] =
{ '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '|', 0, 0 };
char ascii_char;
if (keycode < 66) {
if(keycode < 15 && (qualifier & 0x0007))
ascii_char = sym_translate_table[keycode];
else {
ascii_char = translate_table[keycode];
if (!(qualifier & 0x0007)) /* not a shifted letter */
if(ascii_char >= 'A' && ascii_char <= 'Z')
ascii_char |= 0x0020; /* convert to lower case */
}
if(ascii_char == 8)
return(ascii_char);
}
else
return('\n');
} /* raw_to_ascii */
char
Read_Key_Char(code, qualifier)
USHORT code, qualifier;
{
/* ignore the shift and caps lock keys */
if (code < 0x60 || code > 0x62) {
chr = raw_to_ascii(code, qualifier);
return(chr);
}
else
return('\0');
} /* Read_Key_Char */
void
Write_Window_Char(chr)
char chr;
{
extern void Wrap_It();
Cursor_Toggle();
if(chr == 8) {
if(column) {
column -=8;
Move(myrastport, column, row);
SetDrMd(myrastport, JAM2);
Text(myrastport, " ", 1);
Move(myrastport, column, row);
ctr--;
SetDrMd(myrastport, JAM1);
}
Cursor_Toggle();
return;
}
string[0] = chr;
Move(myrastport, column, row);
if (string[0] != '\n') {
Text(myrastport, string, 1);
line[ctr++] = string[0];
column += COLUMN_SIZE;
if(column >= Window->GZZWidth-8)
Wrap_It();
}
else {
ctr = column = 0;
Next_Line_Down();
}
Cursor_Toggle();
} /* Write_Window_Char */
void
Wrap_It()
{
SHORT where, i;
for(where = ctr; line[where] != ' ' && where > 0; where--);
if(ctr - where <= (ctr/2) + 1) {
Move(myrastport, where*COLUMN_SIZE, row);
for(i=where; i <= ctr+1; i++)
Text(myrastport, " ", 1);
where++;
Next_Line_Down();
column = 0;
Move(myrastport, column, row);
for(i=where; i < ctr; i++)
line[column++] = line[i];
Text(myrastport, line, column);
ctr = column;
column *= COLUMN_SIZE; /* convert columns to pixels */
}
else {
ctr = column = 0;
Next_Line_Down();
}
} /* Wrap_It */
void
main()
{
extern struct IntuiMessage *GetMsg();
struct IntuiMessage *message;
ULONG class;
USHORT code;
USHORT qualifier;
SHORT done = FALSE;
int windowsigbit,
waitsignal,
signal;
if (!Open_Window()) {
printf("Unable to open window\n");
exit(0);
}
setmem(line, 80, '\0');
string[1] = '\0';
Cursor_Toggle();
windowsigbit = Window->UserPort->mp_SigBit;
waitsignal = 1<<windowsigbit;
while(!done) {
oldsize = Window->GZZHeight;
signal = Wait(waitsignal);
if (signal & 1<<windowsigbit) { /* current code */
while (message = GetMsg(Window->UserPort)) {
class = message->Class;
code = message->Code;
qualifier = message->Qualifier;
ReplyMsg(message);
if(class == NEWSIZE) {
if(Window->GZZHeight < oldsize && row > Window->GZZHeight) {
Next_Line_Down(myrastport);
column = 0;
row = (Window->GZZHeight / 8) * 8;
Move(myrastport, column, row);
ClearEOL(myrastport);
Move(myrastport, column, row);
Cursor_Toggle();
}
}
if (class == RAWKEY) {
if(code < 0x80) {
chr = Read_Key_Char(code, qualifier);
if(chr)
Write_Window_Char(chr);
}
}
else if(class == CLOSEWINDOW)
done = TRUE;
if(class == REFRESHWINDOW) {
BeginRefresh(Window);
EndRefresh(Window, TRUE);
}
}
}
}
Close_Window();
exit(0);
} /* main */